package org.threadCase4;

import java.util.IdentityHashMap;
import java.util.Random;

public class RunnableDemo implements Runnable {
    public static int total = 100;
    public static int count = 3;
    public static int min=1;

    @Override
    public void run() {
       synchronized (RunnableDemo.class){
           int max=total-(count-1)*1;
         if (count==0){
             System.out.println(Thread.currentThread().getName()+"没有抢到红包");
         }else {

             if (count==1){
                 System.out.println(Thread.currentThread().getName()+"抢到红包"+total+"元。当前可抢最大金额："+max);
                 count--;
             }else {
                 count--;
                 Random r=new Random();
                 int money=r.nextInt(100);
                 if (money>max){
                     money=max;
                 }else if (money<min){
                     money=min;
                 }
                 total-=money;
                 System.out.println(Thread.currentThread().getName()+"抢到红包"+money+"元。当前可抢最大金额："+max);
             }
         }

       }


    }
}
